package com.ruoyi.web.controller.gxs;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gxs.domain.GxsSports;
import com.ruoyi.gxs.service.IGxsSportsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 体美劳得分Controller
 * 
 * @author 高晓松
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/gxs/sports")
public class GxsSportsController extends BaseController
{
    @Autowired
    private IGxsSportsService gxsSportsService;

    /**
     * 查询体美劳得分列表
     */
//    @PreAuthorize("@ss.hasPermi('gxs:sports:list')")
    @GetMapping("/list")
    public TableDataInfo list(GxsSports gxsSports)
    {
        startPage();
        List<GxsSports> list = gxsSportsService.selectGxsSportsList(gxsSports);
        return getDataTable(list);
    }

    /**
     * 导出体美劳得分列表
     */
//    @PreAuthorize("@ss.hasPermi('gxs:sports:export')")
    @Log(title = "体美劳得分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxsSports gxsSports)
    {
        List<GxsSports> list = gxsSportsService.selectGxsSportsList(gxsSports);
        ExcelUtil<GxsSports> util = new ExcelUtil<GxsSports>(GxsSports.class);
        util.exportExcel(response, list, "体美劳得分数据");
    }

    /**
     * 获取体美劳得分详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gxs:sports:query')")
    @GetMapping(value = "/{gxsId}")
    public AjaxResult getInfo(@PathVariable("gxsId") Long gxsId)
    {
        return success(gxsSportsService.selectGxsSportsByGxsId(gxsId));
    }

    /**
     * 新增体美劳得分
     */
//    @PreAuthorize("@ss.hasPermi('gxs:sports:add')")
    @Log(title = "体美劳得分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxsSports gxsSports)
    {
        return toAjax(gxsSportsService.insertGxsSports(gxsSports));
    }

    /**
     * 修改体美劳得分
     */
//    @PreAuthorize("@ss.hasPermi('gxs:sports:edit')")
    @Log(title = "体美劳得分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxsSports gxsSports)
    {
        return toAjax(gxsSportsService.updateGxsSports(gxsSports));
    }

    /**
     * 删除体美劳得分
     */
//    @PreAuthorize("@ss.hasPermi('gxs:sports:remove')")
    @Log(title = "体美劳得分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gxsIds}")
    public AjaxResult remove(@PathVariable Long[] gxsIds)
    {
        return toAjax(gxsSportsService.deleteGxsSportsByGxsIds(gxsIds));
    }


    /**
     * 我的体美劳得分列表
     */
//    @PreAuthorize("@ss.hasPermi('gxs:sports:list')")
    @GetMapping("/MyList")
    public TableDataInfo MyList(GxsSports gxsSports)
    {
        startPage();
        List<GxsSports> list = gxsSportsService.selectGxsSportsList(gxsSports);

        String username = getUsername();
        for (int i = 0 ; i < list.size(); i++){
            String  userName = list.get(i).getUserName();
            if (!userName.equals(username)) {
                list.remove(i);
                i--;
            }
        }

        return getDataTable(list);
    }
}
